package com.gzsxy.esjy.service.product.controller.api;

import com.gzsxy.esjy.common.base.util.RequestUtil;
import com.gzsxy.esjy.service.base.dto.request.CommentRequest;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.product.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 前台商品评论
 * @date 2022/2/13 20:17
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/api/comment")
@Api("前台评论")
public class ApiCommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/add")
    @ApiOperation("添加评论")
    public DefaultResponse addComment(@RequestBody CommentRequest commentRequest, HttpServletRequest request){
        commentRequest.setUserIp(RequestUtil.getClientIp(request));
        commentService.addComment(commentRequest);
        return DefaultResponse.ok();
    }
}
